package com.antoni.controller;

import com.antoni.pojo.Book;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Author Zhang Chao
 * @Date 2021/5/15 13:56
 * @Version 1.0
 */
public class BookController {

    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public String postBook(ModelMap map, @ModelAttribute @Validated Book book, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            map.addAttribute("action","create");
            return "BOOK_FROM";
        }
        System.out.println(book);
        return "SUCCESS";
    }

}
